// pages/community/article/articleList/index.js
const app = getApp()
var t = getApp(), a = t.requirejs("core"), e = t.requirejs("wxParse/wxParse"), i = t.requirejs("biz/diypage"), s = t.requirejs("biz/diyform"), n = t.requirejs("biz/goodspicker"), o = (t.requirejs("foxui"), 
t.requirejs("jquery"));
Page({
  data: {
    pageIndex:1,
    totalPage:1,
    dataList:[],
    openid:'',//用户id
  },
  onLoad: function (options) {
    if(options.openid){
      this.setData({
        openid:options.openid
      })
    }
    this.getData();
  },
  getData(){
    var t = this;
    a.post("sns/user/get_posts", {
      id:t.data.openid,
      page:t.data.pageIndex
    }, function(res) {
      let total = res.total;
      let size = res.pagesize
      let integer = parseInt(total / size)
      let remainder = (total % size);
      let totalPage = integer;
      if (remainder > 0) {
        totalPage++
      }
      let data=[];
      if(t.data.pageIndex==1){
        data=res.list
      }else{
        data=t.data.dataList.concat(res.list)
      }
      t.setData({
        dataList:data,
        totalPage:totalPage,
      })
    });
  },
  goDetail(e){
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/community/article/index?id='+id,
    })
  },
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let index = this.data.pageIndex;
    index++;
    if (index > this.data.totalPage) {
      this.setData({
        pageIndex: this.data.totalPage
      })
      return
    } else {
      this.setData({
        pageIndex: index
      })
    }
    this.getData();
  },
})